<%--
  User: dw
  Date: 2019/12/16
  Time: 23:13
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>测评</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
</head>
<body>
  <div class="layui-card" style="width: 60%;margin: auto 20%">
    <div class="layui-card-header" style="text-align: center;font-size: 20px;margin-bottom: 2%;background-color: #4e9b63;color:#f0f0f0;font-weight: bold">部门测评</div>
    <div class="layui-card layui-form" lay-filter="component-form-element">
      <div class="layui-card-header">
        编号：${sessionScope.dep.depId}
        &nbsp; &nbsp; &nbsp;
        名称：${sessionScope.dep.depName}
      </div>
    </div>
    <div class="layui-card-body">
      <form class="layui-form" action="" lay-filter="component-form-element">
        <div class="layui-row layui-col-space10 layui-form-item">
          <div class="layui-row layui-col-space10">
            <div class="layui-col-md12">
              <div class="layui-card layui-form" lay-filter="component-form-element" id="vote">

              </div>
            </div>
          </div>
        </div>
        <div class="layui-form-item" style="margin-top: 20%;position: relative;left: 36.1%">
          <div class="layui-input-block"  >
            <button class="layui-btn"lay-submit lay-filter="LAY-vote-submit" style="background-color: #5FB878">提交</button>
          </div>
        </div>
      </form>
    </div>
  </div>

  
  <script src="../../../layuiadmin/layui/layui.js"></script>  
  <script>
  layui.config({
    base: '../../../layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form'], function(){
    var $ = layui.$
    ,admin = layui.admin
    ,element = layui.element
    ,form = layui.form;

    form.render(null, 'component-form-element');
    element.render('breadcrumb', 'breadcrumb');

      //文档加载时加载测评信息
      $(function () {
          //加载测评信息
          $.ajax({
              url: "/vote/loadAllQuestion?voteBy=${sessionScope.dep.depId}",
              data:{},
              dataType:"json",
              type:"post",
              success:function (res) {
                  var questionList = res.questionList;
                  var str = "";
                  for(var i = 0;i < questionList.length; i++){
                      var question = questionList[i];
                      switch(question.queType){
                          //审批题型
                          case 4:
                              str += "<p>"+(i+1)+"、"+question.queTitle+"</p>\n" +
                                  "                <div class='layui-form-item layui-col-space30'>\n" +
                                  "                  <div class='layui-input-block'>\n" +
                                  "                    <div class='layui-input-block'>\n" +
                                  "                      <input type='checkbox' name="+question.queId+" lay-skin='switch' lay-text='"+(res.choiceListAll[0])[0].choContent+"' value='"+(res.choiceListAll[0])[0].choContent+"'>\n" +
                                  "                    </div>\n" +
                                  "                  </div>\n" +
                                  "                </div>";
                              break;
                          //单选
                          case 1:
                              str += "<p>"+(i+1)+"、"+question.queTitle+"</p>\n" +
                                  "                <div class='layui-form-item layui-col-space30'>\n" +
                                  "                    <div class='layui-input-block'>\n";

                              for(var m = 0; m < res.choiceListAll.length;m++){
                                  var choiceList = res.choiceListAll[m];
                                  for(var j = 0; j < choiceList.length; j++){
                                      var choice  = choiceList[j];
                                      if(choice.queId == question.queId){
                                          if(j == 0){
                                              str +=  "<input type='radio'  checked name="+question.queId+" value="+choice.choContent+" title="+choice.choContent+">\n";
                                          }else{
                                              str +=  "<input type='radio' name="+question.queId+" value="+choice.choContent+" title="+choice.choContent+">\n";
                                          }


                                      }
                                  }
                              }
                              str +=   "                    </div>\n" +
                                  "                </div>";
                              break;
                          //多选
                          case 2:
                              str += "<p>"+(i+1)+"、"+question.queTitle+"</p>\n" +
                                  "                <div class='layui-form-item layui-col-space30'>\n" +
                                  "                    <div class=\"layui-input-block\">\n";

                              for(var n = 0; n < res.choiceListAll.length;n++){
                                  var choiceList = res.choiceListAll[n];
                                  for(var x = 0; x < choiceList.length; x++){
                                      var choice  = choiceList[x];
                                      if(choice.queId == question.queId){
                                          str +=  "<input type='checkbox' name="+question.queId+"."+x+" title="+choice.choContent+" value="+choice.choContent+">\n";

                                      }
                                  }
                              }
                              str +=   "                    </div>\n" +
                                  "                </div>";
                              break;
                          //文本
                          case 3:
                              str += "<p>"+(i+1)+"、"+question.queTitle+"</p>\n" +
                                  "                <div class='layui-form-item layui-col-space30'>\n" +
                                  "                    <div class='layui-input-block'>\n";
                              str +=  "<textarea name="+question.queId+" placeholder='' class='layui-textarea'>"+(res.choiceListAll[i])[0].choContent+"</textarea>";

                              str +=   "                    </div>\n" +
                                  "                </div>";
                              break;
                          //下拉
                          case 5:
                              str += "<p>"+(i+1)+"、"+question.queTitle+"</p>\n" +
                                  "                <div class='layui-form-item layui-col-space30'>\n" +
                                  "                    <div class='layui-input-block'>\n" +
                                  " <select name="+question.queId+" lay-verify=''>";

                              for(var b = 0; b < res.choiceListAll.length;b++){
                                  var choiceList = res.choiceListAll[b];
                                  for(var c = 0; c < choiceList.length; c++){
                                      var choice  = choiceList[c];
                                      if(choice.queId == question.queId){
                                          str +=  "<option  value="+choice.choContent+">"+choice.choContent+"</option>";

                                      }
                                  }
                              }
                              str +=   "</select>" +
                                  "</div>\n" +
                                  "                </div>";
                              break;

                      }
                  }

                  $("#vote").html(str);
                  //必须重新加载
                  form.render();
              },
              error:function (e) {
                  console.log(e.responseText)
              }
          });
      });

      //表单提交
      form.on('submit(LAY-vote-submit)', function(obj){
          //用户输入的表单数据
          var data = obj.field;
          console.log(data);
          $.ajax({
              url: "/answer/addAnswer?voteBy=${sessionScope.dep.depId}",
              data:data,
              dataType:"json",
              type:"post",
              success:function (res) {
                  if(res.msg == "ok"){
                      layer.msg("提交成功");
                  }else{
                      layer.msg("提交失败");
                  }
              },
              error:function (e) {
                  console.log(e.responseText)
                  layer.msg("提交失败");
              }
          });
          return false;


      });
  });
  </script>
</body>
</html>